package stundenplan;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import de.app.badresden.R;

public class StundenplanArrayAdapter extends ArrayAdapter<String> {

	private Activity context;
	private List<String> list;
	private List<String> uhrzeit = new ArrayList<String>();

	public StundenplanArrayAdapter(Activity context, List<String> list) {

		super(context, R.layout.stundenplan_listlayout, list);

		this.context = context;
		this.list = list;

		uhrzeit.add("7:45 - 9:15");
		uhrzeit.add("9:45 - 11:15");
		uhrzeit.add("11:45 - 13:15");
		uhrzeit.add("13:45 - 15:15");
		uhrzeit.add("15:30 - 17:00");
		uhrzeit.add("17:15 - 18:45");
		uhrzeit.add("19:00 - 20:30");
	}

	static class ViewHolder {

		protected TextView textViewLinkeSpalte;
		protected TextView textViewRechteSpalte;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		View view = null;

		if (convertView == null) {
			LayoutInflater inflator = context.getLayoutInflater();
			view = inflator.inflate(R.layout.stundenplan_listlayout, null);

			final ViewHolder viewHolder = new ViewHolder();
			viewHolder.textViewLinkeSpalte = (TextView) view.findViewById(R.id.stundenplan_stunde);
			viewHolder.textViewRechteSpalte = (TextView) view
					.findViewById(R.id.stundenplan_vorlesung);
			view.setTag(viewHolder);
		}
		else
			view = convertView;

		ViewHolder holder = (ViewHolder) view.getTag();

		if (position == 0) {
			holder.textViewLinkeSpalte.setText(R.string.stundenplan_stunde);
			holder.textViewLinkeSpalte.setTypeface(null, Typeface.BOLD);
			holder.textViewLinkeSpalte.setTextSize(15);
			
			holder.textViewRechteSpalte.setText(context.getString(R.string.stundenplan_vorlesung));
			holder.textViewRechteSpalte.setTypeface(null, Typeface.BOLD);
			holder.textViewRechteSpalte.setTextSize(15);
		}
		else {
			holder.textViewLinkeSpalte.setText(uhrzeit.get(position - 1).toString());
			holder.textViewRechteSpalte.setText(list.get(position - 1).toString());
		}
		return view;
	}
}
